package org.s3.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.s3.project.entity.ShoppingCart;
import org.s3.project.entity.shopingzailaiyidan;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cfx
 * @version 1.0
 * @Description
 * @date 2025/2/9 9:47
 */
@Mapper
@Repository
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {

    Boolean addShoppingCart(@Param("list") List<ShoppingCart> shoppingCarts);

    @Select("select * from shopping_cart where user_id = #{userId} and dish_id = #{dishId}")
    Boolean selectShoppingCart(@Param("userId") long userId, @Param("dishId") long dishId);

    ////根据当前用户id和菜品id修改当前菜品数量

    public Boolean updateShoppingCart(@Param("list") List<shopingzailaiyidan> shoppingCartList);

    //修改购物车里面的数量
@Update("UPDATE shopping_cart SET  number=#{number} WHERE id=#{id}  AND user_id=#{user_id} ")
public Boolean  updateShoppingCart(@Param("number") Integer number, @Param("user_id") Integer user_id,@Param("id") Integer id);

    //查询购物车里面是否有这件商品了
    @Select("select count(*)  from   shopping_cart  where     user_id =#{user_id}  and dish_id =#{dish_id}")
    int selectSole(@Param("user_id") Integer user_id ,@Param("dish_id") Integer dish_id);

    //批量删除购物车
    Boolean deleteShopings(@Param("ids") List<String> ids);

    @Update("update   shopping_cart set  number=number+1   where  user_id=#{user_id}  and dish_id=#{dish_id}")
    public Boolean updateAddShoping(@Param("user_id") Integer user_id,@Param("dish_id") Integer dish_id);
}
